<!--排课信息-->
<template>
  <div class="app-container">
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          @click="handleSchedule"
          v-hasPermi="['registrar:class:add']"
        >
          一键排课
        </el-button>
      </el-col>

      <right-toolbar :search="false" @queryTable="getList"> </right-toolbar>
    </el-row>

    <el-table
      v-loading="loading"
      :data="scheduleList"
      border
      @selection-change="handleSelectionChange"
    >
      <el-table-column label="上课日期" align="center" prop="name" width="300">
        <template #default="scope">
          <span>
            {{
              scope.row.startTime &&
              scope.row.startTime.slice(0, 10) +
                " ~ " +
                scope.row.endTime.slice(0, 10)
            }}
            {{
              scope.row.circulateType === 2
                ? "(每周" +
                  {
                    1: "一",
                    2: "二",
                    3: "三",
                    4: "四",
                    5: "五",
                    6: "六",
                    7: "日",
                  }[scope.row.weekNum] +
                  ")"
                : "(每天)"
            }}
          </span>
        </template>
      </el-table-column>
      <el-table-column label="授课课程" align="center" prop="courseNameC" />
      <el-table-column label="上课时间" align="center" prop="name">
        <template #default="scope">
          <span>
            {{ scope.row.classStartTime + " ~ " + scope.row.classEndTime }}
          </span>
        </template>
      </el-table-column>
      <el-table-column label="上课教室" align="center" prop="classRoomName" />
      <el-table-column label="主班老师" align="center" prop="teacherName" />
      <el-table-column
        label="助教老师"
        align="center"
        prop="assistantName"
        :show-overflow-tooltip="true"
      />
      <el-table-column label="上课内容" align="center" prop="description" />
      <el-table-column
        label="操作"
        align="center"
        width="120"
        class-name="small-padding fixed-width"
      >
        <template #default="scope">
          <el-button
            link
            type="primary"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['registrar:class:edit']"
          >
            编辑
          </el-button>
          <el-button
            link
            type="primary"
            @click="handleDelete(scope.row)"
            v-hasPermi="['registrar:class:remove']"
            >删除</el-button
          >
        </template>
      </el-table-column>
    </el-table>
    <Schedule
      :title="title"
      :btn="btn"
      :refresh="true"
      v-bind="$props"
      ref="scheduleRef"
      @refreshPage="getList"
    />
  </div>
</template>

<script setup>
import Schedule from "./schedule.vue";

import {
  getScheduleListAPI,
  deleteScheduleAPI,
} from "@/api/registrar/schedule";

const props = defineProps({
  courseFilterIds: {
    type: String,
  },
  classId: {
    type: String,
  },
  isVip: {
    type: String,
  },
});

const { proxy } = getCurrentInstance();
const scheduleList = ref([]);
const loading = ref(false);
const title = ref("");
const btn = ref("");
const scheduleRef = ref(null);

// 方法-------------------------------------------------------------------------------------------------------------
function getList() {
  loading.value = true;
  getScheduleListAPI({
    classId: props.classId,
    pageSize: 9999,
    pageNum: 1,
  }).then((response) => {
    scheduleList.value = response.rows;
    loading.value = false;
  });
}

function handleDelete(row) {
  proxy.$modal
    .confirm('是否确认删除"' + row.courseName + '"？')
    .then(function () {
      return deleteScheduleAPI({ id: row.id });
    })
    .then(() => {
      getList();
      proxy.$modal.msgSuccess("删除成功");
    })
    .catch(() => {});
}

function handleSchedule() {
  title.value = "新增排课";
  btn.value = "生成排课";
  scheduleRef.value.openW();
}

function handleUpdate(row) {
  title.value = "编辑排课";
  btn.value = "保存";
  scheduleRef.value.getScheduleDetail(row.id);
}

//调用---------------------------------------------------------------------------------------------------------------
getList();
</script>

<style scoped lang="scss">
.el-table__row .el-form-item {
  margin: 0;
}
</style>
